import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.EmptyBorder;

import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.listeners.MessageListener;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Bank;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.methods.GrandExchange.GEItem;
import org.rsbot.script.wrappers.RSArea;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSGroundItem;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSItem;
import org.rsbot.script.wrappers.RSModel;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSTile;

//TODO: Hovering
@ScriptManifest(authors = { "Muse" }, keywords = "Mining", name = "GK Miner Pro", version = 1.21, description = "An AIO Miner by Muse. All options are in the GUI.")
public class GKMinerPro extends Script implements PaintListener,
		MessageListener {

	public static interface GameConstants {
		RSArea GUILD = new RSArea(3016, 9730, 3055, 9756);
		RSArea ESS = new RSArea(2870, 4790, 2950, 4870);
	}

	// Variables
	public GKGUI gui;
	private RSModel highlight;
	int strangeRock[] = { 15532, 15533 };
	final int[] gemID = { 1617, 1619, 1621, 1623 };
	final int[] pickaxe = { 1265, 1267, 1269, 1271, 1273, 1275, 1296, 13661,
			14107, 380302, 379433, 379181, 14664, 2528 };
	final int[] ores = { 434, 453, 449, 436, 444, 440, 447, 451, 442, 438,
			6983, 6981, 6979, 6977, 6971, 6973, 6975 };
	int rocksMined = 0,
			miningCount,
			aub = 553, // teleport
			fail, gemsMined = 0, fails, levelsGained = 0, bankID, banker,
			cskill, ore, ustairs, umstairs = 6226, door = 11680,
			dwDoor = 11715, dstairs;
	String Location, location = "", Rock = "", status = "", rockSelected = "";
	int[] rock;
	private RSTile[] rock_tiles;
	private RSObject lastRock, over;
	public static final int DIST_EXPONENT = 2;
	public static final int MAX_OTHER_DIST = 10;
	public static final int MY_PLAYER_WEIGHT = 2;
	final int miningAnimation = 625;
	final int essRock = 2491;
	final int portal = 2492;
	final int[] miningAnimations = { 624, 625, 626, 627, 629 };
	public boolean powerMine, mining, startScript = false;
	final ScriptManifest properties = getClass().getAnnotation(
			ScriptManifest.class);

	// AntiBan
	GKMinerAntiBan antiban;
	Thread t;

	// Paint Variables
	long startTime = System.currentTimeMillis(), runTime;
	int expPerHour, expGained, startExp, moneyMade, oreProfit, profitPerHour,
			oresPerHour, oreValue;
	// Paths
	public RSTile bankTile;
	public RSTile aubTile = new RSTile(3253, 3402);
	public RSTile rTile = new RSTile(3053, 9823);
	public RSTile mineTile, RockLoc, rockTile, stairTile, doorTile, dladTile,
			uladTile;
	public RSTile[] bankToMine;
	public RSTile[] toRock;
	public RSTile[] toDoor;
	public RSTile[] toLad;
	public RSTile[] ipath = { new RSTile(3053, 9825), new RSTile(3041, 9829),
			new RSTile(3031, 9827) };
	public RSTile[] ladToBank;
	public RSTile[] toStair;
	public RSTile[] toBank;
	public RSTile[] bankToLad;
	public RSTile[] mineToBank;

	public double version = getClass().getAnnotation(ScriptManifest.class)
			.version();

	public boolean onStart() {
		URLConnection url = null;
		BufferedReader in = null;
		BufferedWriter out = null;
		if (JOptionPane
				.showConfirmDialog(
						null,
						"Would you like to check for updates?\nThis requires an internet connection and will write files to your hard drive.") == 0) {
			try {
				url = new URL(
						"http://famousscripts.webs.com/scripts/MinerVERSION.txt")
						.openConnection();
				in = new BufferedReader(new InputStreamReader(url
						.getInputStream()));
				if (Double.parseDouble(in.readLine()) > version) {
					if (JOptionPane
							.showConfirmDialog(null,
									"There is a new update available. Would you like to download it?") == 0) {
						JOptionPane
								.showMessageDialog(null,
										"Please choose 'GKMinerPro.java' in your scripts folder and hit 'Open'");
						JFileChooser fc = new JFileChooser();
						if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
							url = new URL(
									"http://famousscripts.webs.com/scripts/GKMinerPro.java")
									.openConnection();
							in = new BufferedReader(new InputStreamReader(url
									.getInputStream()));
							out = new BufferedWriter(new FileWriter(fc
									.getSelectedFile().getPath()));
							String inp;
							while ((inp = in.readLine()) != null) {
								out.write(inp);
								out.newLine();
								out.flush();
							}
							log("Script successfully downloaded. Please recompile and reload the script.");
							return false;
						} else
							log("Update canceled");
					} else
						log("Update canceled");
				} else
					JOptionPane.showMessageDialog(null,
							"You have the latest version.");
				if (in != null)
					in.close();
				if (out != null)
					out.close();
			} catch (IOException e) {
				log("Could not retrieve version.");
				return false;
			}
		}

		gui = new GKGUI();
		gui.setVisible(true);
		while (!startScript) {
			sleep(10);
		}
		status = "Starting up";
		antiban = new GKMinerAntiBan();
		t = new Thread(antiban);
		mouse.setSpeed(random(6, 8));
		rocksMined = 0;
		miningCount = 0;
		levelsGained = 0;
		gemsMined = 0;
		startExp = 0;
		if (canEquip()) {
			wieldPick();
		}
		final GEItem oress = grandExchange.lookup(ore);
		oreValue = oress.getMarketPrice();

		if (game.getCurrentTab() != Game.TAB_INVENTORY) {
			sleep(random(200, 400));
			game.openTab(Game.TAB_INVENTORY);
			sleep(random(200, 400));
		}
		game.setChatOption(7, Game.CHAT_MODE.OFF);
		startScript = true;

		return true;
	}

	private boolean bank() {
		if (interfaces.get(Bank.INTERFACE_BANK).isValid()) {
			bank.depositAllExcept(pickaxe);
			sleep(random(1900, 2100));
		} else {
			openBank();
		}
		return false;
	}

	public boolean canEquip() {
		if (skills.getCurrentLevel(Skills.ATTACK) >= 60
				&& inventory.containsOneOf(pickaxe[9])
				|| skills.getCurrentLevel(Skills.ATTACK) >= 60
				&& inventory.containsOneOf(pickaxe[8])
				|| skills.getCurrentLevel(Skills.ATTACK) >= 60
				&& inventory.containsOneOf(pickaxe[7])
				|| skills.getCurrentLevel(Skills.ATTACK) >= 60
				&& inventory.containsOneOf(pickaxe[6])
				|| skills.getCurrentLevel(Skills.ATTACK) >= 40
				&& inventory.containsOneOf(pickaxe[5])
				|| skills.getCurrentLevel(Skills.ATTACK) >= 30
				&& inventory.containsOneOf(pickaxe[4])
				|| skills.getCurrentLevel(Skills.ATTACK) >= 20
				&& inventory.containsOneOf(pickaxe[3])
				|| skills.getCurrentLevel(Skills.ATTACK) >= 5
				&& inventory.containsOneOf(pickaxe[2])
				|| skills.getCurrentLevel(Skills.ATTACK) >= 1
				&& inventory.containsOneOf(pickaxe[1])
				|| skills.getCurrentLevel(Skills.ATTACK) >= 1
				&& inventory.containsOneOf(pickaxe[0])) {
			return true;
		}
		return false;
	}

	public boolean atInventoryItem(int i, String s) {
		if (game.getCurrentTab() != Game.TAB_INVENTORY) {
			game.openTab(Game.TAB_INVENTORY);
		}
		return inventory.getItem(i).doAction(s);

	}

	public int wieldPick() {
		if (interfaces.get(Bank.INTERFACE_BANK).isValid()) {
			bank.close();
		}
		if (skills.getCurrentLevel(Skills.ATTACK) >= 60
				&& inventory.containsOneOf(pickaxe[9])) {
			atInventoryItem(pickaxe[9], "ield");
		} else if (skills.getCurrentLevel(Skills.ATTACK) >= 60
				&& inventory.containsOneOf(pickaxe[8])) {
			atInventoryItem(pickaxe[8], "ield");
		} else if (skills.getCurrentLevel(Skills.ATTACK) >= 60
				&& inventory.containsOneOf(pickaxe[7])) {
			atInventoryItem(pickaxe[7], "ield");
		} else if (skills.getCurrentLevel(Skills.ATTACK) >= 60
				&& inventory.containsOneOf(pickaxe[6])) {
			atInventoryItem(pickaxe[6], "ield");
		} else if (skills.getCurrentLevel(Skills.ATTACK) >= 40
				&& inventory.containsOneOf(pickaxe[5])) {
			atInventoryItem(pickaxe[5], "ield");
		} else if (skills.getCurrentLevel(Skills.ATTACK) >= 30
				&& inventory.containsOneOf(pickaxe[4])) {
			atInventoryItem(pickaxe[4], "ield");
		} else if (skills.getCurrentLevel(Skills.ATTACK) >= 20
				&& inventory.containsOneOf(pickaxe[3])) {
			atInventoryItem(pickaxe[3], "ield");
		} else if (skills.getCurrentLevel(Skills.ATTACK) >= 5
				&& inventory.containsOneOf(pickaxe[2])) {
			atInventoryItem(pickaxe[2], "ield");
		} else if (skills.getCurrentLevel(Skills.ATTACK) >= 1
				&& inventory.containsOneOf(pickaxe[1])) {
			atInventoryItem(pickaxe[1], "ield");
		} else if (skills.getCurrentLevel(Skills.ATTACK) >= 1
				&& inventory.containsOneOf(pickaxe[0])) {
			atInventoryItem(pickaxe[0], "ield");
		}
		return random(200, 400);
	}

	private boolean gettingAttacked() {
		return players.getMyPlayer().isInCombat();
	}

	public boolean isAni() {
		if (players.getMyPlayer().getAnimation() == miningAnimation
				|| players.getMyPlayer().getAnimation() == 626
				|| players.getMyPlayer().getAnimation() == 624
				|| players.getMyPlayer().getAnimation() == 6752
				|| players.getMyPlayer().getAnimation() == 627) {
			return true;
		}
		return false;
	}

	public boolean hoverObject(RSObject object) {
		if (object == null) {
			return false;
		}
		if (object != null) {
			try {
				object.doHover();
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		return false;
	}

	public void teleport() {
		RSNPC npc = npcs.getNearest(aub);
		if (npc != null) {
			if (!npc.isOnScreen()) {
				camera.turnToCharacter(npc, 10);
			} else if (npc.doAction("Teleport")) {
				sleep(1000);
				if (!getMyPlayer().isIdle()) {
					sleep(2000);
				}
				sleep(1000);
			}
		}
	}

	private void strangeRock() {
		RSItem str = inventory.getItem(strangeRock);
		RSInterface inf = interfaces.get(94);
		RSComponent child;
		if (inventory.containsOneOf(strangeRock)) {
			status = "Destroying strange rock";
			str.doAction("Destroy");
			child = inf.getComponent(0);
			if (child != null && child.isValid()) {
				if (child.doAction("Continue")) {
					sleep(900);
				}
			}
		}
	}

	public boolean miningEss() {
		boolean working = false;
		for (int i = 0; i < 5; i++) {
			if (getMyPlayer().getAnimation() != -1) {
				working = true;
				break;
			}
			sleep(random(200, 250));
		}
		return working;
	}

	public void mineEss() {
		RSObject obj = objects.getNearest(essRock);
		if (obj != null) {
			if (obj.isOnScreen() && !miningEss()) {
				if (obj.doAction("Mine")) {
					sleep(1500);
					if (getMyPlayer().isMoving()) {
						sleep(2000);
					}
				} else if (fails > 5) {
					camera.turnToObject(obj, 10);
					fails = 0;
				} else {
					++fails;
				}
			} else if (!getMyPlayer().isMoving()
					&& !miningEss()
					&& (walking.walkTo(obj.getLocation()) || walking
							.walkTileMM(walking.getClosestTileOnMap(obj
									.getLocation())))) {
				sleep(random(1000, 1800));
			}
		}
	}

	public void goPortal() {
		RSObject obj = objects.getNearest(portal);
		if (obj != null) {
			if (obj.isOnScreen()) {
				if (obj.doAction("Enter")) {
					sleep(1000);
					if (getMyPlayer().isMoving()) {
						sleep(2000);
					}
				} else if (fails > 5) {
					camera.turnToObject(obj, 10);
					fails = 0;
				} else {
					++fails;
				}
			} else if (!getMyPlayer().isMoving()
					&& (walking.walkTo(obj.getLocation()) || walking
							.walkTileMM(walking.getClosestTileOnMap(obj
									.getLocation())))) {
				sleep(random(1000, 1800));
			}
		}
	}

	public boolean mineRocks() {
		try {
			final RSObject Rock = objects.getNearest(rock);
			highlight = Rock.getModel();
			if (Rock == null) {
				return false;

			} else {
				if (!isAni() && Rock != null) {
					if (Rock.doAction("Mine")) {
						sleep(random(1800, 2200));
						return true;
					}
				}
			}
		} catch (Exception ignored) {

		}
		return false;
	}

	public int drop() {
		RSGroundItem pick = groundItems.getNearest(pickaxe);
		strangeRock();
		while (inventory.contains(ore)) {
			inventory.dropAllExcept(pickaxe);
		}
		if (pick != null && !inventory.isFull()) {
			status = "Picking up pickaxe";
			pick.doAction("Take");
		}
		return random(510, 760);
	}

	private enum State {
		MINE, BANK, WALKTOBANK, AUBTOBANK, PORTAL, MINEESS, AUBURY, WRONGTILE, DROP, TODOOR, WALKTOLAD, TOBANK, LADTOBANK, BANKTOLAD, UPLADDER, DOWNLADDER, AVOID, WALKTOSTAIR, WALKTOMINE, WALKTOROCK, OPENDOOR, UPSTAIRS, DOWNSTAIRS, WAIT
	}

	private State getState() {
		RSObject dd = objects.getNearest(dwDoor);
		final String loc = (String) gui.location.getSelectedItem();
		final String ro = (String) gui.Rock.getSelectedItem();
		try {
			if (!powerMine && inventory.isFull()
					&& calc.distanceTo(bankTile) <= 5) {
				return State.BANK;
			} else if (powerMine && inventory.isFull()) {
				return State.DROP;
			} else if (!loc.equals("Varrock Essence") && !inventory.isFull()
					&& calc.distanceTo(mineTile) <= 15) {
				return State.MINE;
			} else if (loc.equals("Dwarven Mines")
					&& calc.distanceTo(doorTile) <= 5 && dd == null) {
				return State.OPENDOOR;
			} else if (loc.equals("Varrock Essence")
					&& GameConstants.ESS.contains(getMyPlayer().getLocation())
					&& inventory.isFull()) {
				return State.PORTAL;
			} else if (loc.equals("Varrock Essence")
					&& !GameConstants.ESS.contains(getMyPlayer().getLocation())
					&& inventory.isFull()) {
				return State.AUBTOBANK;
			} else if (loc.equals("Mining Guild")
					&& calc.distanceTo(dladTile) <= 5 && inventory.isFull()) {
				return State.UPLADDER;
			} else if (!powerMine && !loc.equals("Mining Guild")
					&& !loc.equals("Varrock Essence")
					&& !loc.equals("Dwarven Mines") && inventory.isFull()
					&& calc.distanceTo(bankTile) >= 5) {
				return State.WALKTOBANK;
			} else if (loc.equals("Mining Guild") && !powerMine
					&& calc.distanceTo(stairTile) <= 4 && !inventory.isFull()
					|| loc.equals("Dwarven Mines") && !powerMine
					&& calc.distanceTo(stairTile) <= 4 && !inventory.isFull()) {
				return State.WALKTOROCK;
			} else if (loc.equals("Mining Guild") && !powerMine
					&& calc.distanceTo(bankTile) >= 50
					&& calc.distanceTo(dladTile) >= 4 && inventory.isFull()) {
				return State.WALKTOLAD;
			} else if (loc.equals("Mining Guild")
					&& inventory.isFull()
					&& !GameConstants.GUILD.contains(getMyPlayer()
							.getLocation())) {
				return State.LADTOBANK;
			} else if (loc.equals("Mining Guild")
					&& !inventory.isFull()
					&& calc.distanceTo(uladTile) >= 5
					&& !GameConstants.GUILD.contains(getMyPlayer()
							.getLocation())) {
				return State.BANKTOLAD;
			} else if (loc.equals("Dwarven Mines") && inventory.isFull()
					&& calc.distanceTo(doorTile) <= 5) {
				return State.TOBANK;
			} else if (!inventory.isFull() && calc.distanceTo(bankTile) <= 6
					&& calc.distanceTo(doorTile) >= 5) {
				return State.TODOOR;
			} else if (!powerMine && !inventory.isFull()
					&& calc.distanceTo(bankTile) <= 5) {
				return State.WALKTOMINE;
			} else if (calc.distanceTo(doorTile) <= 5 && dd != null
					&& !inventory.isFull()) {
				return State.DOWNSTAIRS;
			} else if (loc.equals("Mining Guild")
					&& calc.distanceTo(uladTile) <= 5 && !inventory.isFull()) {
				return State.DOWNLADDER;
			} else if (!powerMine && calc.distanceTo(stairTile) <= 5
					&& inventory.isFull()) {
				return State.UPSTAIRS;
			} else if (!powerMine && calc.distanceTo(bankTile) >= 50
					&& calc.distanceTo(stairTile) >= 4 && inventory.isFull()) {
				return State.WALKTOSTAIR;
			} else if (ro.equals("Iron") && loc.equals("Dwarven Mines")
					&& calc.distanceTo(rTile) <= 6 && inventory.getCount() >= 2) {
				return State.WRONGTILE;
			} else if (gettingAttacked()) {
				return State.AVOID;
				// //////////////ESSENCE/////////////////////////////
			} else if (loc.equals("Varrock Essence")
					&& calc.distanceTo(aubTile) <= 5 && !inventory.isFull()) {
				return State.AUBURY;
			} else if (loc.equals("Varrock Essence")
					&& GameConstants.ESS.contains(getMyPlayer().getLocation())
					&& !inventory.isFull()) {
				return State.MINEESS;
			}
		} catch (final Exception e) {
			e.printStackTrace();
		}
		return State.WAIT;
	}

	// Loop
	public int loop() {
		if (!t.isAlive()) {
			t.start();
			log("Antiban Started.");
		}

		if (players.getMyPlayer().getAnimation() == miningAnimation
				|| players.getMyPlayer().getAnimation() == 624
				|| players.getMyPlayer().getAnimation() == 626
				|| players.getMyPlayer().getAnimation() == 627) {
			return 1800;
		}
		if (interfaces.get(211).containsText("You need a Pickaxe to mine")) {
			log("You do not have a pickaxe. Stopping Script.");
			stopScript();
		}
		switch (getState()) {
		case MINE:
			final String loc = (String) gui.location.getSelectedItem();
			status = "Mining";
			if (walking.getEnergy() >= random(24, 32)) {
				walking.setRun(true);
			}
			if (loc.equals("Mining Guild")
					&& !GameConstants.GUILD.contains(getMyPlayer()
							.getLocation())) {
				walking.walkTileMM(mineTile);
			}
			mineRocks();
			break;
		case DROP:
			status = "Dropping Ore";
			drop();
			break;
		case BANK:
			status = "Banking";
			bank();
			break;
		case AUBURY:
			status = "Teleporting to Mine";
			teleport();
			break;
		case MINEESS:
			status = "Mining Essence";
			mineEss();
			break;
		case AUBTOBANK:
			status = "Walking to Bank";
			walkPath(mineToBank);
			break;
		case PORTAL:
			status = "Using Portal";
			miningCount = 0;
			goPortal();
			break;
		case OPENDOOR: // Dwarven Mines
			status = "Opening Door";
			RSObject doors = objects.getNearest(door);
			if (doors != null && doors.isOnScreen()) {
				highlight = doors.getModel();
				if (doors.doAction("Open")) {
					sleep(4500);
					highlight = null;
				}
			}
			break;
		case WALKTOBANK:
			status = "Walking to Bank";
			walkPath(mineToBank);
			break;
		case WALKTOMINE:
			status = "Walking to Mine";
			walkPath(bankToMine);
			walking.walkTileMM(mineTile);
			break;
		case WALKTOROCK:
			status = "Walking to Rocks";
			walkPath(toRock);
			walking.walkTileMM(mineTile);
			break;
		case UPLADDER:
			RSObject umstair = objects.getNearest(umstairs);
			status = "Going up Ladder";
			if (umstair != null && umstair.isOnScreen()) {
				highlight = umstair.getModel();
				if (umstair.doAction("Climb")) {
					sleep(4500);
					highlight = null;
				}
			}
			break;
		case BANKTOLAD:
			status = "Walking to Ladder";
			walkPath(bankToLad);
			break;
		case LADTOBANK:
			status = "Walking To Bank";
			walkPath(ladToBank);
			break;
		case TOBANK:
			status = "Walking to Bank";
			walkPath(toBank);
			break;
		case TODOOR:
			status = "Walking to Door";
			walkPath(toDoor);
			break;
		case WALKTOSTAIR:
			status = "Walking to Stairs";
			walkPath(toStair);
			break;
		case WALKTOLAD:
			status = "Walking to Ladder";
			walkPath(toLad);
			break;
		case DOWNLADDER:
			RSObject dstair = objects.getNearest(dstairs);
			status = "Going down Ladder";
			if (dstair != null && dstair.isOnScreen()) {
				highlight = dstair.getModel();
				if (dstair.doAction("Climb")) {
					sleep(4500);
					highlight = null;
				}
			}
			break;
		case UPSTAIRS:
			RSObject ustai = objects.getNearest(ustairs);
			status = "Going up Stairs";
			if (ustai != null && ustai.isOnScreen()) {
				highlight = ustai.getModel();
				if (ustai.doAction("Climb")) {
					sleep(4500);
					highlight = null;
				}
			}
			break;
		case DOWNSTAIRS:
			RSObject dstai = objects.getNearest(dstairs);
			status = "Going down Stairs";
			if (dstai != null && dstai.isOnScreen()) {
				highlight = dstai.getModel();
				if (dstai.doAction("Climb")) {
					sleep(4500);
					highlight = null;
				}
			}
			break;
		case WRONGTILE:
			walkPath(ipath);
			break;
		case AVOID:
			status = "Avoiding Combat";
			walking.walkTileMM(mineTile);
			break;
		case WAIT:
			break;
		}
		return 100;
	}

	// onFinish
	public void onFinish() {
		antiban.stopThread = true;
		log("Thank You for using GK Miner Pro!");
		log("Ores Mined: " + rocksMined);
		log("EXP Gained: " + expGained);
		log("Levels Gained: " + levelsGained);
	}

	// Credits to purefocus for progress bar.
	public void ProgBar(Graphics g, int posX, int posY, int width, int height,
			int Progress, Color color1, Color color2, Color text) {
		int[] c1 = { color1.getRed(), color1.getGreen(), color1.getBlue(), 150 };
		int[] c2 = { color2.getRed(), color2.getGreen(), color2.getBlue(), 150 };
		if (c1[0] > 230) {
			c1[0] = 230;
		}
		if (c1[1] > 230) {
			c1[1] = 230;
		}
		if (c1[2] > 230) {
			c1[2] = 230;
		}
		if (c2[0] > 230) {
			c2[0] = 230;
		}
		if (c2[1] > 230) {
			c2[1] = 230;
		}
		if (c2[2] > 230) {
			c2[2] = 230;
		}
		g.setColor(new Color(c1[0], c1[1], c1[2], 200));
		g.fillRoundRect(posX, posY, width, height, 5, 12);
		g.setColor(new Color(c1[0] + 25, c1[1] + 25, c1[2] + 25, 200));
		g.fillRoundRect(posX, posY, width, height / 2, 5, 12);
		g.setColor(new Color(c2[0], c2[1], c2[2], 200));
		g.fillRoundRect(posX, posY, (Progress * width) / 100, height, 5, 12);
		g.setColor(new Color(c2[0] + 25, c2[1] + 25, c2[2] + 25, 150));
		g
				.fillRoundRect(posX, posY, (Progress * width) / 100,
						height / 2, 5, 12);
		g.setColor(Color.LIGHT_GRAY);
		g.drawRoundRect(posX, posY, width, height, 5, 12);
		g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, height));
		g.setColor(text);
		g.drawString(Progress + "%", posX + (width / 6), posY
				+ (height + height / 20));
	}

	// Paint
	public static final Color ROCKCOVER = new Color(0, 0, 255, 100);
	private final Font font3 = new Font("Ti89pc", 1, 12);

	public void onRepaint(final Graphics g) {
		((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		if (!startScript) {
			status = "Loading GUI";
			return;
		}
		RSModel r = highlight;
		if (r != null) {
			g.setColor(ROCKCOVER);
			for (Polygon p : r.getTriangles()) {
				g.fillPolygon(p);
			}
		}
		// ///////////////Paint Mouse////////////////
		Point m = mouse.getLocation();
		g.setColor(Color.red);
		g.drawRoundRect(m.x - 6, m.y, 15, 3, 5, 5);
		g.drawRoundRect(m.x, m.y - 6, 3, 15, 5, 5);
		g.setColor(Color.red);
		g.fillRoundRect(m.x - 6, m.y, 15, 3, 5, 5);
		g.fillRoundRect(m.x, m.y - 6, 3, 15, 5, 5);
		// //////////////////////////////////////////
		if (startExp == 0) {
			startExp = skills.getCurrentExp(Skills.MINING);
		}
		runTime = System.currentTimeMillis() - startTime;
		final String loc = (String) gui.location.getSelectedItem();
		oreProfit = rocksMined * oreValue;
		long millis = System.currentTimeMillis() - startTime;
		final long hours = millis / (1000 * 60 * 60);
		millis -= hours * 1000 * 60 * 60;
		profitPerHour = (int) (3600000.0 / runTime * oreProfit);
		expGained = skills.getCurrentExp(Skills.MINING) - startExp;
		oresPerHour = (int) ((3600000.0 / (double) runTime) * rocksMined);
		expGained = skills.getCurrentExp(Skills.MINING) - startExp;
		expPerHour = (int) ((3600000.0 / (double) runTime) * expGained);
		if (loc.equals("Varrock Essence")) {
			rocksMined = expGained / 5;
		}
		final long minutes = millis / (1000 * 60);
		millis -= minutes * 1000 * 60;
		final long seconds = millis / 1000;
		final int xx = 561;
		final int yy = 225;
		final int percent = skills.getPercentToNextLevel(Skills.MINING);

		ProgBar(g, 11, 323, 145, 11, percent, Color.black, Color.red,
				Color.white);

		// ///Status Bar////
		g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 13));
		g.setColor(Color.BLACK);
		g.drawRoundRect(330 - 15, 336 - 15, 200, 15, 10, 10);
		g.setColor(new Color(0, 0, 0, 90));
		g.fillRoundRect(330 - 15, 336 - 15, 200, 15, 10, 10);
		g.setColor(Color.WHITE);
		g.drawString(status, 330, 336 - 3);
		g.drawString("Status: ", 270, 336 - 3);
		// ////////////////////////////////////
		g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 11));
		g.setColor(new Color(0, 0, 0, 175));
		g.fillRoundRect(555, 210, 175, 250, 10, 10);
		g.setColor(Color.black);
		g.drawString("GK Miner Version "
				+ Double.toString(properties.version()), xx + 1, yy + 1);
		g.setColor(Color.white);
		g.drawString("GK Miner Version "
				+ Double.toString(properties.version()), xx, yy);
		g.setColor(Color.white);
		g.drawString("Time Running: " + hours + ":" + minutes + ":" + seconds
				+ "", 561, 265);
		g.drawString("Location: " + Location + "", 561, 285);
		g.drawString("Chosen Rock: " + rockSelected + "", 561, 305);
		if ((powerMine)) {
			g.drawString("Mode: Power Mining", 561, 325);
		} else {
			if ((!powerMine)) {
				g.drawString("Mode: Banking", 561, 325);
			}
		}
		g.drawString("Current Mining Level: "
				+ skills.getCurrentLevel(Skills.MINING) + "", 561, 345);
		if (!loc.equals("Varrock Essence")) {
			g.drawString("Ores Mined/Hr: " + Integer.toString(rocksMined)
					+ " / " + oresPerHour + "", 561, 365);
		}
		if (loc.equals("Varrock Essence")) {
			g.drawString("Essence Mined/Hr: " + Integer.toString(rocksMined)
					+ " / " + oresPerHour + "", 561, 365);
		}
		g.drawString("Levels Gained: " + Integer.toString(levelsGained) + "",
				561, 385);
		g.drawString("Exp Gained/Hr: " + expGained + " / " + expPerHour + "",
				561, 405);
		g.drawString("EXP Till Next Level: "
				+ skills.getExpToNextLevel(Skills.MINING) + "", 561, 425);
		g.drawString("Gems Mined: " + Integer.toString(gemsMined) + "", 561,
				445);
		g.setFont(font3);
		g.setColor(Color.red);
		g.drawString("GameKiller.net", 415, 471);
	}

	public boolean waitForBankInt(int timeout) {
		final long start = System.currentTimeMillis();
		while (System.currentTimeMillis() - start < timeout) {
			if (!players.getMyPlayer().isMoving()
					&& (System.currentTimeMillis() - start) > 1200)
				return false;

			if (bank.isOpen())
				return true;

			sleep(15);
		}
		return false;
	}

	public boolean openBank() {
		final RSObject bank = objects.getNearest(bankID);
		if (bank == null) {
			return false;
		}
		if (!calc.tileOnScreen(bank.getLocation())) {
			camera.turnToTile(bank.getLocation(), 15);
		}
		if (tiles.doAction(bank.getLocation(), "Use-quickly")) {
			waitForBankInt(random(5000, 7000));
		}
		return true;
	}

	// Server Messages
	public void messageRecieved(final MessageEvent arg0) {
		final String serverString = arg0.getMessage();
		if (interfaces.canContinue()) {
			interfaces.clickContinue();
		}
		if (serverString.contains("You've just advanced")) {
			levelsGained++;
		}
		if (serverString.contains("need to have completed the Rune")) {
			log("You must complete the Rune Mysteries quest first.");
			stopScript();
		}
		if (serverString.contains("You manage to mine")) {
			rocksMined++;
		}
		if (serverString.contains("You just found a")) {
			gemsMined++;
		}
		if (serverString.contains("you are dead!")) {
			log("You just died. Stopping script for safety purposes.");
			stopScript();
		}
	}

	private int start(final RSTile[] path) {
		int start = 0;
		for (int a = path.length - 1; a > 0; a--) {
			if (tileOnMinimap(path[a])) {
				start = a;
				break;
			}
		}
		return start;
	}

	private boolean tileOnMinimap(final RSTile tile) {
		final Point p = calc.tileToMinimap(tile);
		return Math.sqrt(Math.pow(627 - p.x, 2) + Math.pow(85 - p.y, 2)) < random(
				60, 74);
	}

	private RSTile checkTile(final RSTile tile) {
		if (calc.tileOnMap(tile)) {
			return tile;
		}
		final RSTile loc = players.getMyPlayer().getLocation();
		final RSTile walk = new RSTile((loc.getX() + tile.getX()) / 2, (loc
				.getY() + tile.getY()) / 2);
		return calc.tileOnMap(walk) ? walk : checkTile(walk);
	}

	private boolean walkPath(final RSTile[] path) {
		for (int i = start(path); i < path.length; i++) {
			if (!walking.isRunEnabled() && walking.getEnergy() > random(40, 60)) {
				mouse.click(random(707, 762), random(90, 121), true);
			}
			walking.walkTo(path[i]);
			sleep(2000);
			if (path[i] == path[path.length - 1]) {
				break;
			}
			while (!tileOnMinimap(path[i + 1])) {
				if (!players.getMyPlayer().isMoving()) {
					walking.walkTo(checkTile(path[i + 1]));
				}
			}
		}
		return calc.distanceTo(path[path.length - 1]) <= 4;
	}

	private class GKMinerAntiBan implements Runnable {
		public boolean stopThread;

		public void run() {
			while (!stopThread) {
				try {
					if (random(0, 15) == 0) {
						final char[] LR = new char[] { KeyEvent.VK_LEFT,
								KeyEvent.VK_RIGHT };
						final char[] UD = new char[] { KeyEvent.VK_DOWN,
								KeyEvent.VK_UP };
						final char[] LRUD = new char[] { KeyEvent.VK_LEFT,
								KeyEvent.VK_RIGHT, KeyEvent.VK_UP,
								KeyEvent.VK_UP };
						final int random2 = random(0, 2);
						final int random1 = random(0, 2);
						final int random4 = random(0, 4);

						if (random(0, 3) == 0) {
							mouse.moveSlightly();
							keyboard.pressKey(LR[random1]);
							Thread.sleep(random(100, 400));
							keyboard.pressKey(UD[random2]);
							Thread.sleep(random(300, 600));
							keyboard.releaseKey(UD[random2]);
							Thread.sleep(random(100, 400));
							keyboard.releaseKey(LR[random1]);

							if (random(0, 8) == 0) {
								if (game.getCurrentTab() != 1) {
									game.openTab(1);
									Thread.sleep(random(2000, 3000));
								}
							}

							if (random(0, 10) == 0) {
								// hoverPlayer();
								// Thread.sleep(random(750, 3000));
								// while (menu.isOpen()) {
								// mouse.moveRandomly(750);
								// Thread.sleep(random(100, 500));
								game.openTab(random(0, 14));
							}
						} else {
							keyboard.pressKey(LRUD[random4]);
							if (random4 > 1) {
								Thread.sleep(random(300, 600));
							} else {
								Thread.sleep(random(500, 900));
							}
							keyboard.releaseKey(LRUD[random4]);
						}
					} else {
						Thread.sleep(random(200, 2000));
					}
				} catch (final Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	/**
	 * @author Muse
	 */
	public class GKGUI extends JFrame {

		private static final long serialVersionUID = 1L;

		public GKGUI() {
			initComponents();
		}

		private void initComponents() {
			// JFormDesigner - Component initialization - DO NOT MODIFY
			// //GEN-BEGIN:initComponents
			dialogPane = new JPanel();
			contentPanel = new JPanel();
			tabbedPane2 = new JTabbedPane();
			panel1 = new JPanel();
			Rock = new JComboBox();
			label1 = new JLabel();
			label2 = new JLabel();
			location = new JComboBox();
			checkBox2 = new JCheckBox();
			panel2 = new JPanel();
			label3 = new JLabel();
			label4 = new JLabel();
			buttonBar = new JPanel();
			okButton = new JButton();
			cancelButton = new JButton();

			// ======== this ========
			setTitle("GK Miner GUI");
			Container contentPane = getContentPane();
			contentPane.setLayout(new BorderLayout());

			// ======== dialogPane ========
			{
				dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
				dialogPane.setLayout(new BorderLayout());

				// ======== contentPanel ========
				{
					contentPanel.setLayout(null);

					// ======== tabbedPane2 ========
					{

						// ======== panel1 ========
						{
							panel1.setLayout(null);

							// ---- Rock ----
							Rock.setModel(new DefaultComboBoxModel(
									new String[] { "Tin", "Copper", "Clay",
											"Iron", "Coal", "Essence",
											"Pure Essence", "Gold", "Silver",
											"Mithril", "Adamantite" }));
							panel1.add(Rock);
							Rock.setBounds(0, 40, 80, 20);
							Rock.addActionListener(new ActionListener() {
								public void actionPerformed(
										final ActionEvent evt) {
									final String ro = (String) Rock
											.getSelectedItem();
									if (ro == "Tin") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] {
																"East Varrock",
																"West Varrock",
																"West Lumbridge",
																"Dwarven Mines",
																"Rimmington",
																"Al Kharid",
																"West Falador",
																"Barbarian Village",
																"Power",
																"Edgeville Dungeon" }));
									} else if (ro == "Copper") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] {
																"East Varrock",
																"West Falador",
																"West Lumbridge",
																"Dwarven Mines",
																"Al Kharid",
																"Rimmington",
																"Power",
																"Edgeville Dungeon" }));
									} else if (ro == "Iron") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] {
																"East Varrock",
																"West Varrock",
																"Al Kharid",
																"Dwarven Mines",
																"Rimmington",
																"West Falador",
																"Power",
																"Edgeville Dungeon" }));
									} else if (ro == "Coal") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] {
																"Al Kharid",
																"West Falador",
																"Draynor",
																"Mining Guild",
																"Barbarian Village",
																"Dwarven Mines",
																"Power",
																"Edgeville Dungeon" }));
									} else if (ro == "Essence") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] { "Varrock Essence" }));
									} else if (ro == "Pure Essence") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] { "Varrock Essence" }));
									} else if (ro == "Gold") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] {
																"Rimmington",
																"Power",
																"Dwarven Mines" }));
									} else if (ro == "Silver") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] {
																"Al Kharid",
																"West Varrock",
																"Power",
																"Edgeville Dungeon" }));
									} else if (ro == "Mithril") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] {
																"Al Kharid",
																"Draynor",
																"Mining Guild",
																"Power",
																"Edgeville Dungeon" }));
									} else if (ro == "Adamantite") {
										location
												.setModel(new javax.swing.DefaultComboBoxModel(
														new String[] {
																"Al Kharid",
																"Edgeville Dungeon",
																"Power",
																"Dwarven Mines" }));
									}
								}
							});

							// ---- label1 ----
							label1.setText("Rock");
							label1
									.setFont(new Font("DokChampa", Font.BOLD,
											11));
							panel1.add(label1);
							label1.setBounds(0, 10, 40, 35);

							// ---- label2 ----
							label2.setText("Location");
							label2
									.setFont(new Font("DokChampa", Font.BOLD,
											11));
							panel1.add(label2);
							label2.setBounds(new Rectangle(new Point(100, 20),
									label2.getPreferredSize()));

							// ---- location ----
							location
									.setModel(new javax.swing.DefaultComboBoxModel(
											new String[] { "East Varrock",
													"West Varrock",
													"Varrock Essence",
													"Rimmington", "Al Kharid",
													"Dwarven Mines",
													"West Falador",
													"Mining Guild",
													"West Lumbridge",
													"Draynor",
													"Barbarian Village",
													"Power",
													"Edgeville Dungeon" }));

							panel1.add(location);
							location.setBounds(100, 40, 90, location
									.getPreferredSize().height);

							// ---- checkBox2 ----
							checkBox2.setText("Enable PowerMining?");
							panel1.add(checkBox2);
							checkBox2.setBounds(new Rectangle(new Point(5, 90),
									checkBox2.getPreferredSize()));

							{ // compute preferred size
								Dimension preferredSize = new Dimension();
								for (int i = 0; i < panel1.getComponentCount(); i++) {
									Rectangle bounds = panel1.getComponent(i)
											.getBounds();
									preferredSize.width = Math
											.max(bounds.x + bounds.width,
													preferredSize.width);
									preferredSize.height = Math.max(bounds.y
											+ bounds.height,
											preferredSize.height);
								}
								Insets insets = panel1.getInsets();
								preferredSize.width += insets.right;
								preferredSize.height += insets.bottom;
								panel1.setMinimumSize(preferredSize);
								panel1.setPreferredSize(preferredSize);
							}
						}
						tabbedPane2.addTab("Mining", panel1);

						// ======== panel2 ========
						{
							panel2.setLayout(null);

							// ---- label3 ----
							label3.setText("Muse");
							label3.setFont(new Font("Cambria", Font.BOLD, 12));
							panel2.add(label3);
							label3.setBounds(0, 0,
									label3.getPreferredSize().width, 15);

							// ---- label4 ----
							label4.setText("GameKiller.net");
							label4.setFont(new Font("Cambria", Font.BOLD, 12));
							panel2.add(label4);
							label4.setBounds(new Rectangle(new Point(0, 25),
									label4.getPreferredSize()));

							{ // compute preferred size
								Dimension preferredSize = new Dimension();
								for (int i = 0; i < panel2.getComponentCount(); i++) {
									Rectangle bounds = panel2.getComponent(i)
											.getBounds();
									preferredSize.width = Math
											.max(bounds.x + bounds.width,
													preferredSize.width);
									preferredSize.height = Math.max(bounds.y
											+ bounds.height,
											preferredSize.height);
								}
								Insets insets = panel2.getInsets();
								preferredSize.width += insets.right;
								preferredSize.height += insets.bottom;
								panel2.setMinimumSize(preferredSize);
								panel2.setPreferredSize(preferredSize);
							}
						}
						tabbedPane2.addTab("Credits", panel2);

					}
					contentPanel.add(tabbedPane2);
					tabbedPane2.setBounds(5, 0, 365, 205);

					{ // compute preferred size
						Dimension preferredSize = new Dimension();
						for (int i = 0; i < contentPanel.getComponentCount(); i++) {
							Rectangle bounds = contentPanel.getComponent(i)
									.getBounds();
							preferredSize.width = Math.max(bounds.x
									+ bounds.width, preferredSize.width);
							preferredSize.height = Math.max(bounds.y
									+ bounds.height, preferredSize.height);
						}
						Insets insets = contentPanel.getInsets();
						preferredSize.width += insets.right;
						preferredSize.height += insets.bottom;
						contentPanel.setMinimumSize(preferredSize);
						contentPanel.setPreferredSize(preferredSize);
					}
				}
				dialogPane.add(contentPanel, BorderLayout.CENTER);

				// ======== buttonBar ========
				{
					buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
					buttonBar.setLayout(new GridBagLayout());
					((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {
							0, 85, 80 };
					((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {
							1.0, 0.0, 0.0 };

					// ---- okButton ----
					okButton.setText("OK");
					buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1,
							0.0, 0.0, GridBagConstraints.CENTER,
							GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0,
							0));
					okButton
							.addActionListener(new java.awt.event.ActionListener() {

								public void actionPerformed(
										java.awt.event.ActionEvent evt) {
									StartActionPerformed(evt);
								}
							});

					// ---- cancelButton ----
					cancelButton.setText("Cancel");
					buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1,
							1, 0.0, 0.0, GridBagConstraints.CENTER,
							GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0,
							0));
				}
				dialogPane.add(buttonBar, BorderLayout.SOUTH);
			}
			contentPane.add(dialogPane, BorderLayout.CENTER);
			pack();
			setLocationRelativeTo(getOwner());
			// //GEN-END:initComponents
		}

		private void StartActionPerformed(java.awt.event.ActionEvent evt) {
			String loc = (String) location.getSelectedItem();
			String ro = (String) Rock.getSelectedItem();
			if (checkBox2.isSelected()) {
				powerMine = true;
			} else {
				powerMine = false;
			}
			if (loc.equals("East Varrock")) {
				Location = "East Varrock";
				bankID = 11402;
				banker = 5912;
				bankToMine = new RSTile[] { new RSTile(3254, 3421),
						new RSTile(3262, 3429), new RSTile(3274, 3429),
						new RSTile(3283, 3427), new RSTile(3286, 3415),
						new RSTile(3291, 3407), new RSTile(3292, 3394),
						new RSTile(3293, 3387), new RSTile(3291, 3375),
						new RSTile(3285, 3366) };
				mineToBank = walking.reversePath(bankToMine);
				bankTile = new RSTile(3253, 3421);

			} else if (loc.equals("Power")) {
				Location = "N/A (PowerMining)";

			} else if (loc.equals("Varrock Essence")) {
				Location = "Varrock Essence";
				bankID = 11402;
				bankTile = new RSTile(3253, 3421);
				bankToMine = new RSTile[] { new RSTile(3253, 3421),
						new RSTile(3258, 3410), new RSTile(3253, 3402) };
				mineToBank = walking.reversePath(bankToMine);

			} else if (loc.equals("West Varrock")) {
				Location = "West Varrock";
				bankID = 11402;
				banker = 5912;
				bankToMine = new RSTile[] { new RSTile(3184, 3436),
						new RSTile(3176, 3429), new RSTile(3167, 3419),
						new RSTile(3169, 3409), new RSTile(3169, 3399),
						new RSTile(3175, 3389), new RSTile(3179, 3383),
						new RSTile(3182, 3372) };
				mineToBank = walking.reversePath(bankToMine);
				bankTile = new RSTile(3185, 3435);

			} else if (loc.equals("Rimmington")) {
				Location = "Rimmington";
				bankID = 11758;
				bankToMine = new RSTile[] { new RSTile(3012, 3356),
						new RSTile(3007, 3350), new RSTile(3007, 3339),
						new RSTile(3007, 3327), new RSTile(3005, 3317),
						new RSTile(3004, 3306), new RSTile(2998, 3295),
						new RSTile(2995, 3286), new RSTile(2993, 3273),
						new RSTile(2992, 3261), new RSTile(2981, 3257),
						new RSTile(2976, 3250), new RSTile(2971, 3241) };
				mineToBank = walking.reversePath(bankToMine);
				bankTile = new RSTile(3012, 3356);

			} else if (loc.equals("Al Kharid")) {
				Location = "Al Kharid";
				bankID = 35647;
				bankToMine = new RSTile[] { new RSTile(3270, 3167),
						new RSTile(3276, 3174), new RSTile(3283, 3185),
						new RSTile(3282, 3196), new RSTile(3279, 3209),
						new RSTile(3277, 3220), new RSTile(3275, 3231),
						new RSTile(3278, 3242), new RSTile(3278, 3252),
						new RSTile(3282, 3262), new RSTile(3288, 3272),
						new RSTile(3296, 3279), new RSTile(3298, 3293),
						new RSTile(3300, 3304), new RSTile(3297, 3312) };
				mineToBank = walking.reversePath(bankToMine);
				bankTile = new RSTile(3270, 3168);

			} else if (loc.equals("West Falador")) {
				Location = "West Falador";

			} else if (loc.equals("Dwarven Mines")) {
				Location = "Dwarven Mines";
				bankID = 11758;
				toDoor = new RSTile[] { new RSTile(3013, 3356),
						new RSTile(3022, 3362), new RSTile(3030, 3360),
						new RSTile(3040, 3359), new RSTile(3053, 3364),
						new RSTile(3061, 3373) };
				toBank = walking.reversePath(toDoor);
				stairTile = new RSTile(3058, 9776);
				bankTile = new RSTile(3012, 3356);
				doorTile = new RSTile(3061, 3374);
				ustairs = 30943;
				dstairs = 30944;

			} else if (loc.equals("West Lumbridge")) {
				Location = "West Lumbridge";

			} else if (loc.equals("Draynor")) {
				Location = "Draynor";
				bankID = 2213;
				bankToMine = new RSTile[] { new RSTile(3093, 3243),
						new RSTile(3100, 3235), new RSTile(3109, 3229),
						new RSTile(3121, 3226), new RSTile(3130, 3219),
						new RSTile(3136, 3209), new RSTile(3140, 3199),
						new RSTile(3144, 3189), new RSTile(3147, 3182),
						new RSTile(3149, 3169), new RSTile(3150, 3158),
						new RSTile(3147, 3148) };
				mineToBank = walking.reversePath(bankToMine);
				bankTile = new RSTile(3093, 3243);

			} else if (loc.equals("Barbarian Village")) {
				Location = "Barbarian Village";
				bankID = 26972;
				bankToMine = new RSTile[] { new RSTile(3094, 3490),
						new RSTile(3086, 3500), new RSTile(3074, 3504),
						new RSTile(3073, 3496), new RSTile(3071, 3481),
						new RSTile(3071, 3468), new RSTile(3073, 3455),
						new RSTile(3068, 3443), new RSTile(3069, 3434),
						new RSTile(3071, 3421), new RSTile(3082, 3422) };
				mineToBank = walking.reversePath(bankToMine);
				bankTile = new RSTile(3094, 3490);

			} else if (loc.equals("Edgeville Dungeon")) {
				Location = "Edgeville Dungeon";
				bankID = 11402;
				bankTile = new RSTile(3185, 3435);

			} else if (loc.equals("Mining Guild")) {
				Location = "Mining Guild";
				bankID = 11758;
				ladToBank = new RSTile[] { new RSTile(3021, 3339),
						new RSTile(3032, 3338), new RSTile(3031, 3348),
						new RSTile(3025, 3360), new RSTile(3013, 3356) };
				bankToLad = walking.reversePath(ladToBank);
				dladTile = new RSTile(3021, 9739);
				stairTile = new RSTile(3021, 9739);
				uladTile = new RSTile(3021, 3339);
				dstairs = 2113;
				bankTile = new RSTile(3012, 3356);
			}

			if (ro.equals("Tin")) {
				ore = 438;
				rockSelected = "Tin";
				rock = new int[] { 9714, 9716, 31077, 31078, 11933, 11934,
						11935, 11958, 11959, 5778, 5776, 11957, 29227, 29229 };
			} else if (ro.equals("Copper")) {
				ore = 436;
				rockSelected = "Copper";
				rock = new int[] { 9708, 9709, 9710, 31080, 31081, 31082,
						11936, 11937, 11938, 11960, 5779, 5780, 5781, 11962,
						11961, 29230, 29231 };
			} else if (ro.equals("Iron")) {
				ore = 440;
				rockSelected = "Iron";
				rock = new int[] { 11954, 11955, 11956, 9719, 9717, 9718,
						29221, 29222, 29223, 31071, 31072, 31073, 37307, 37308,
						37309, 5774, 5775 };
			} else if (ro.equals("Gold")) {
				ore = 444;
				rockSelected = "Gold";
				rock = new int[] { 9720, 9722, 37310, 37312 };
			} else if (ro.equals("Coal")) {
				ore = 453;
				rockSelected = "Coal";
				rock = new int[] { 31070, 31068, 31069, 11930, 11931, 11963,
						11964, 11932, 29215, 29216, 29217, 5770, 5771, 5772 };
			} else if (ro.equals("Essence")) {
				ore = 1436;
				rockSelected = "Rune Essence";
			} else if (ro.equals("Pure Essence")) {
				ore = 7936;
				rockSelected = "Pure Essence";
			} else if (ro.equals("Clay")) {
				ore = 434;
				rockSelected = "Clay";
				rock = new int[] { 31062, 31063, 15503, 5766, 5767, 15505,
						9711, 9713 };
			} else if (ro.equals("Adamantite")) {
				ore = 449;
				rockSelected = "Adamantite";
				rock = new int[] { 11939, 11941, 29233, 29235, 31083, 5782,
						5783, 31085 };
			} else if (ro.equals("Silver")) {
				ore = 442;
				rockSelected = "Silver";
				rock = new int[] { 37304, 37305, 37306, 11948, 11949, 29224,
						29225, 29226, 11950 };
			} else if (ro.equals("Mithril")) {
				ore = 447;
				rockSelected = "Mithril";
				rock = new int[] { 11942, 11944, 11943, 29236, 32438, 32439,
						31086, 31087, 31088, 5784, 5785, 5786 };
			}

			// Mine Tile Check
			if (loc.equals("East Varrock") && (ro.equals("Tin"))) {
				mineTile = new RSTile(3283, 3363);
			} else if (loc.equals("East Varrock") && (ro.equals("Copper"))) {
				mineTile = new RSTile(3287, 3363);
			} else if (loc.equals("East Varrock") && (ro.equals("Iron"))) {
				mineTile = new RSTile(3286, 3368);
				// ////////////////////////
				// /////Al Kharid//////////
				// ////////////////////////
			} else if (loc.equals("Al Kharid") && (ro.equals("Copper"))) {
				mineTile = new RSTile(3297, 3314);
			} else if (loc.equals("Al Kharid") && (ro.equals("Iron"))) {
				mineTile = new RSTile(3298, 3311);
			} else if (loc.equals("Al Kharid") && (ro.equals("Adamantite"))) {
				mineTile = new RSTile(3299, 3316);
			} else if (loc.equals("Al Kharid") && (ro.equals("Silver"))) {
				mineTile = new RSTile(3302, 3313);
			} else if (loc.equals("Al Kharid") && (ro.equals("Coal"))) {
				mineTile = new RSTile(3300, 3299);
			} else if (loc.equals("Al Kharid") && (ro.equals("Mithril"))) {
				mineTile = new RSTile(3302, 3305);
			} else if (loc.equals("Al Kharid") && (ro.equals("Tin"))) {
				mineTile = new RSTile(3299, 3316);
				// /////////////////////////
				// /////Rimmington//////////
				// /////////////////////////
			} else if (loc.equals("Rimmington") && (ro.equals("Gold"))) {
				mineTile = new RSTile(2979, 3234);
			} else if (loc.equals("Rimmington") && (ro.equals("Tin"))) {
				mineTile = new RSTile(2986, 3237);
			} else if (loc.equals("Rimmington") && (ro.equals("Iron"))) {
				mineTile = new RSTile(2971, 3240);
			} else if (loc.equals("Rimmington") && (ro.equals("Copper"))) {
				mineTile = new RSTile(2979, 3246);
			} else if (loc.equals("Rimmington") && (ro.equals("Clay"))) {
				mineTile = new RSTile(2986, 3237);
				// /////////////////////////
				// /////West Varrock////////
				// /////////////////////////
			} else if (loc.equals("West Varrock") && (ro.equals("Silver"))) {
				mineTile = new RSTile(3177, 3367);
			} else if (loc.equals("West Varrock") && (ro.equals("Clay"))) {
				mineTile = new RSTile(3180, 3371);
			} else if (loc.equals("West Varrock") && (ro.equals("Tin"))) {
				mineTile = new RSTile(3182, 3376);
			} else if (loc.equals("West Varrock") && (ro.equals("Iron"))) {
				mineTile = new RSTile(3175, 3367);
				// /////////////////////////
				// /////West Lumbridge//////
				// /////////////////////////
			} else if (loc.equals("West Lumbridge") && (ro.equals("Tin"))) {
				mineTile = new RSTile(3227, 3417);
			} else if (loc.equals("West Lumbridge") && (ro.equals("Copper"))) {
				mineTile = new RSTile(3228, 3417);
				// ///////////////////////////
				// //////////Essence/////////
				// ///////////////////////////
			} else if (loc.equals("Varrock Essence") && (ro.equals("Essence"))) {
				mineTile = new RSTile(3253, 3402);
			} else if (loc.equals("Varrock Essence")
					&& (ro.equals("Pure Essence"))) {
				mineTile = new RSTile(3253, 3402);
				// /////////////////////////
				// /////West Falador//////
				// /////////////////////////
			} else if (loc.equals("West Falador") && (ro.equals("Iron"))) {
				mineTile = new RSTile(2904, 3355);
			} else if (loc.equals("West Falador") && (ro.equals("Coal"))) {
				mineTile = new RSTile(2909, 3362);
			} else if (loc.equals("West Falador") && (ro.equals("Tin"))) {
				mineTile = new RSTile(2906, 3359);
			} else if (loc.equals("West Falador") && (ro.equals("Copper"))) {
				mineTile = new RSTile(2908, 3361);
				// /////////////////////////
				// ///////Draynor///////////
				// /////////////////////////
			} else if (loc.equals("Draynor") && (ro.equals("Coal"))) {
				mineTile = new RSTile(3146, 3150);
			} else if (loc.equals("Draynor") && (ro.equals("Mithril"))) {
				mineTile = new RSTile(3146, 3147);
			} else if (loc.equals("Draynor") && (ro.equals("Adamantite"))) {
				mineTile = new RSTile(3147, 3147);
				// /////////////////////////
				// ////Barbarian Village////
				// /////////////////////////
			} else if (loc.equals("Barbarian Village") && (ro.equals("Tin"))) {
				mineTile = new RSTile(3080, 3419);
			} else if (loc.equals("Barbarian Village") && (ro.equals("Coal"))) {
				mineTile = new RSTile(3082, 3422);
				// //////////////////////////
				// ////Dungeon///////////////
				// //////////////////////////
			} else if (loc.equals("Edgeville Dungeon") && (ro.equals("Coal"))) {
				mineTile = new RSTile(3137, 9869);
			} else if (loc.equals("Edgeville Dungeon")
					&& (ro.equals("Mithril"))) {
				mineTile = new RSTile(3135, 9871);
			} else if (loc.equals("Edgeville Dungeon")
					&& (ro.equals("Adamantite"))) {
				mineTile = new RSTile(3139, 9873);
			} else if (loc.equals("Edgeville Dungeon") && (ro.equals("Iron"))) {
				mineTile = new RSTile(3139, 9873);
			} else if (loc.equals("Edgeville Dungeon") && (ro.equals("Tin"))) {
				mineTile = new RSTile(3139, 9873);
			} else if (loc.equals("Edgeville Dungeon") && (ro.equals("Copper"))) {
				mineTile = new RSTile(3141, 9879);
			} else if (loc.equals("Edgeville Dungeon") && (ro.equals("Silver"))) {
				mineTile = new RSTile(3137, 9879);
				// /////////////////////////
				// /////Mining Guild////////
				// /////////////////////////
			} else if (loc.equals("Mining Guild") && (ro.equals("Mithril"))) {
				toRock = new RSTile[] { new RSTile(3021, 9739),
						new RSTile(3032, 9739), new RSTile(3040, 9740),
						new RSTile(3047, 9740) };
				mineTile = new RSTile(3049, 9736);
				toLad = walking.reversePath(toRock);
			} else if (loc.equals("Mining Guild") && (ro.equals("Coal"))) {
				toRock = new RSTile[] { new RSTile(3021, 9739),
						new RSTile(3032, 9739), new RSTile(3040, 9740) };
				mineTile = new RSTile(3040, 9740);
				toLad = walking.reversePath(toRock);
				// /////////////////////////
				// /////Dwarven Mine////////
				// /////////////////////////
			} else if (loc.equals("Dwarven Mines") && (ro.equals("Coal"))) {
				mineTile = new RSTile(3052, 9776);
				toRock = new RSTile[] { new RSTile(3058, 9776),
						new RSTile(3051, 9777) };
			} else if (loc.equals("Dwarven Mines") && (ro.equals("Tin"))) {
				mineTile = new RSTile(3054, 9782);
				toRock = new RSTile[] { new RSTile(3058, 9776),
						new RSTile(3050, 9782) };
			} else if (loc.equals("Dwarven Mines") && (ro.equals("Adamantite"))) {
				toRock = new RSTile[] { new RSTile(3058, 9776),
						new RSTile(3049, 9778), new RSTile(3042, 9771) };
				mineTile = new RSTile(3042, 9771);
				toStair = walking.reversePath(toRock);
			} else if (loc.equals("Dwarven Mines") && (ro.equals("Gold"))) {
				toRock = new RSTile[] { new RSTile(3058, 9776),
						new RSTile(3052, 9771), new RSTile(3045, 9761) };
				mineTile = new RSTile(3049, 9761);
				toStair = walking.reversePath(toRock);
			} else if (loc.equals("Dwarven Mines") && (ro.equals("Iron"))) {
				toRock = new RSTile[] { new RSTile(3058, 9776),
						new RSTile(3049, 9778), new RSTile(3042, 9786),
						new RSTile(3042, 9795), new RSTile(3041, 9806),
						new RSTile(3039, 9817), new RSTile(3039, 9828),
						new RSTile(3032, 9825) };
				toStair = walking.reversePath(toRock);
				mineTile = new RSTile(3032, 9825);
			} else if (loc.equals("Dwarven Mines") && (ro.equals("Copper"))) {
				toRock = new RSTile[] { new RSTile(3058, 9776),
						new RSTile(3049, 9778), new RSTile(3042, 9786),
						new RSTile(3042, 9795), new RSTile(3041, 9806),
						new RSTile(3044, 9812), new RSTile(3050, 9816) };
				mineTile = new RSTile(3053, 9819);
				toStair = walking.reversePath(toRock);
			}
			startScript = true;
			gui.setVisible(false);
		}

		// JFormDesigner - Variables declaration - DO NOT MODIFY
		// //GEN-BEGIN:variables
		private JPanel dialogPane;
		private JPanel contentPanel;
		private JTabbedPane tabbedPane2;
		private JPanel panel1;
		private JComboBox Rock;
		private JLabel label1;
		private JLabel label2;
		private JComboBox location;
		private JCheckBox checkBox2;
		private JPanel panel2;
		private JLabel label3;
		private JLabel label4;
		private JPanel buttonBar;
		private JButton okButton;
		private JButton cancelButton;
		// JFormDesigner - End of variables declaration //GEN-END:variables
	}

	@Override
	public void messageReceived(MessageEvent e) {
		// TODO Auto-generated method stub

	}
}
